#include "object.h"

namespace Core{
    //============================= LIFECYCLE ====================================
    Object::Object(const QString &filename):	parentSquare(0),
                                                //mesh(NULL),
                                                scale(1.0),
                                                drawAabb(false)
    {
        //setMesh(filename);
    }

    Object::Object(const Object &ref):	Drawable(ref),
                                        parentSquare(ref.parentSquare),
                                        //mesh(ref.mesh),
                                        scale(ref.scale),
                                        drawAabb(ref.drawAabb)
    {}

    //============================= OPERATIONS ===================================
    void Object::draw() const
    {
        drawWithTexture();
    }
/*
    void Object::setMesh(const QString &filename)
    {
        if(mesh != 0) removeMesh();
        if(filename != ""){
            MeshManager::instance().addMesh(filename,mesh);
            aabb.setMesh(m_Mesh);
        }
    }

    void Object::removeMesh()
    {
        if(mesh != 0) {
            MeshManager::instance().removeMesh(mesh);
            mesh = 0;
            aabb.reset();
        }
    }
*/
    void Object::drawWithTexture() const
    {/*
        glPushMatrix();
            glTranslated(0.0,-deltaTranslateY(),0.0);
            glScaled(scale,scale,scale);
            glColor4d(1.0,1.0,1.0,1.0);
            texture->apply();
            if(mesh != 0)
            {
                mesh->draw();
                if(drawAabb)
                {
                    aabb.draw();
                }
            }
            else
            {
                glutSolidSphere(0.2,10,10);
            }
            texture->unApply();
        glPopMatrix();*/
    }

    void Object::drawWithColor() const
    {/*
        glPushMatrix();
            glTranslated(0.0,-deltaTranslateY(),0.0);
            glScaled(scale,scale,scale);
            float32 color[] = { static_cast<float>(color.x()), static_cast<float>(color.y()),
                                static_cast<float>(color.z()), static_cast<float>(color.w()) };
            glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,color);
            glColor4d(color.x(),color.y(),color.z(),color.w());
            if(mesh != 0){
                mesh->draw();
                if(drawAabb) aabb.draw();
            }else{
                glutSolidSphere(0.2,10,10);
            }
        glPopMatrix();*/
    }

    void Object::drawIn2D() const
    {
        //todo: use img2d
    }
}
